﻿using AutoMapper;
using MediatR;
using T_settlement.API.Application.Command.PaymentCommand;
using T_settlement.Domain;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.PaymentCommandHandlers
{
    public class AddsPaymentCommandHandlers:IRequestHandler<AddsPaymentCommand,int>
    {
        private readonly IPaymentRepository paymentRepository;
        private readonly IMapper mapper;

        public AddsPaymentCommandHandlers(IPaymentRepository paymentRepository, IMapper mapper)
        {
            this.paymentRepository = paymentRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(AddsPaymentCommand request, CancellationToken cancellationToken)
        {
            var info = mapper.Map<Payment>(request);
            info.CreateBy = "王小宝";
            info.CreateDate = DateTime.Now;
            info.AuditState = request.AuditState = -1;//待提交
            return await paymentRepository.AddAsync(info);




             //return await paymentRepository.AddAsync(info);
            //var info = new Payment();
            //info.Title = request.Title;
            //info.Description = request.Description;
            //info.PaymentMoney = request.PaymentMoney;
            //info.SettlType = request.SettlType;
            //info.Tinning = request.Tinning;
            //info.Bank = request.Bank;
            //info.BankAccount = request.BankAccount;
            //info.CreateBy = "王小宝";
            //info.PaymentTime = request.PaymentTime;
            //info.Remark = request.Remark;
            //info.CreateDate = DateTime.Now;
            //info.AuditState = request.AuditState = -1;//待提交
            //info.InvoiceImg = request.InvoiceImg;
            //return await paymentRepository.AddAsync(info);
        }
    }
}
